//
//  CYTabBarController.m
//  baisibudejie
//
//  Created by 陈雨 on 16/6/10.
//  Copyright © 2016年 CY. All rights reserved.
//

#import "CYTabBarController.h"
#import "CYEssenceViewController.h"
#import "CYMeViewController.h"
#import "CYNewViewController.h"
#import "CYPublishViewController.h"
#import "CYFriendViewController.h"
#import "UIImage+image.h"

@implementation CYTabBarController

+ (void)load{
    //获取全局的TabBarItem
    UITabBarItem *item = [UITabBarItem appearance];
    
    //设置选中状态下的TabBarbutton
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:attr forState:UIControlStateSelected];
    
    //设置正常状态下的TabBarButton
    NSMutableDictionary *atrrFont = [NSMutableDictionary dictionary];
    atrrFont[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    [item setTitleTextAttributes:atrrFont forState:UIControlStateNormal];
}
- (void)viewDidLoad{
    [super viewDidLoad];
    //1.添加所有的子控制器
    [self setUpAllChildVC];
    //2.设置TabBar上所有的按钮的内容,
    [self setUpAllTabBarButton];
}
- (void)setUpAllTabBarButton{
    //精华
    UINavigationController *nav0 = self.childViewControllers[0];
    nav0.tabBarItem.title = @"精华";
    nav0.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    nav0.tabBarItem.selectedImage = [UIImage imagewithOrignalImageNamed:@"tabBar_essence_click_icon"];
    
    //新帖
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"新帖";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    nav1.tabBarItem.selectedImage = [UIImage imagewithOrignalImageNamed:@"tabBar_new_click_icon"];
    
    //发布
    UIViewController *publish = self.childViewControllers[2];
//    publish.tabBarItem.title = @"发布";
    publish.tabBarItem.image = [UIImage imagewithOrignalImageNamed:@"tabBar_publish_icon"];
    publish.tabBarItem.selectedImage = [UIImage imagewithOrignalImageNamed:@"tabBar_publish_click_icon"];
    //设置按钮图片的位置
    publish.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
    
    //关注
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"关注";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    nav3.tabBarItem.selectedImage = [UIImage imagewithOrignalImageNamed:@"tabBar_friendTrends_click_icon"];
    
    //我
    UINavigationController *nav4 = self.childViewControllers[4];
    nav4.tabBarItem.title = @"我";
    nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    nav4.tabBarItem.selectedImage = [UIImage imagewithOrignalImageNamed:@"tabBar_me_click_icon"];
}
- (void)setUpAllChildVC{
    //精华
    UIViewController *essenceVC = [[UIViewController alloc] init];
    essenceVC.view.backgroundColor = [UIColor redColor];
    UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:essenceVC];
    [self addChildViewController:naviVC];
    
    //新帖
    UIViewController *newVC = [[UIViewController alloc] init];
    newVC.view.backgroundColor = [UIColor orangeColor];
    UINavigationController *naviVC2 = [[UINavigationController alloc] initWithRootViewController:newVC];
    [self addChildViewController:naviVC2];
    
    //发布
    UIViewController *publishVC = [[UIViewController alloc] init];
    publishVC.view.backgroundColor = [UIColor cyanColor];
    UINavigationController *naviVC3 = [[UINavigationController alloc] initWithRootViewController:publishVC];
    [self addChildViewController:naviVC3];
    
    //关注
    UIViewController *friTrendVC = [[UIViewController alloc] init];
    friTrendVC.view.backgroundColor = [UIColor yellowColor];
    UINavigationController *naviVC4 = [[UINavigationController alloc] initWithRootViewController:friTrendVC];
    [self addChildViewController:naviVC4];
    
    //我
    UIViewController *meVC = [[UIViewController alloc] init];
    meVC.view.backgroundColor = [UIColor blueColor];
    UINavigationController *naviVC5 = [[UINavigationController alloc] initWithRootViewController:meVC];
    [self addChildViewController:naviVC5];
    

    
}
@end
